<?php

/**
 * @author Samphors CHHEAN
 * @copyright 2014
 */
 
class Model_jobs extends CI_Model {
   
    /* This function use to retrieve all categories and count categories
     * $this->model_jobs->browse_jobs_by_category();
     */
    public function browse_jobs_by_category(){
        $query = $this -> db -> query('SELECT c.job_category_id, c.name, c.job_categories_keys, IFNULL(a.counts,0) AS count_jobs
           FROM mw_job_categories AS c LEFT JOIN (
           SELECT using_job_category_id, COUNT( * ) AS counts
           FROM mw_job_ads where mw_job_ads.status = 1 and date_available>=CURDATE() GROUP BY using_job_category_id
           ) AS a ON c.job_category_id = a.using_job_category_id
           ORDER BY c.job_category_id ');
        return $query;    
    }
     /* This function use to retrieve all locations and count
     * $this->model_jobs->brow_jobs_by_location();
     */
    public function brow_jobs_by_location(){
        $query = $this -> db -> query('SELECT l.name, l.job_location_id, IFNULL(a.counts,0) AS countlocations
           FROM mw_job_locations AS l LEFT JOIN (
           SELECT using_job_location_id, COUNT( * ) AS counts
           FROM mw_job_ads where mw_job_ads.status = 1 and date_available>=CURDATE() GROUP BY using_job_location_id
           ) AS a ON l.job_location_id = a.using_job_location_id
           ORDER BY l.job_location_id');
        return $query;  
    }
     /* This function use to retrieve all companies and count
     * $this->model_jobs->brow_jobs_by_company();
     */
    public function brow_jobs_by_company(){
        $query = $this -> db -> query('SELECT c.name as name ,c.company_keys as company_key , IFNULL(a.counts,0) AS countcompany
           FROM mw_companies AS c 
		   Inner JOIN mw_employers as e ON e.employer_id = c.using_employer_id
		   Inner JOIN (
           SELECT using_employer_id, COUNT( * ) AS counts
           FROM mw_job_ads where mw_job_ads.status = 1 and date_available>=CURDATE()
           and using_employer_id != 0
           GROUP BY using_employer_id
           ) AS a ON e.employer_id = a.using_employer_id
           ORDER BY c.company_id');
        return $query;
    }
    /* This function use to retrieve recently jobs or lastest jobs
     * $this->model_jobs->list_lastest_jobs();
     */
    public function list_lastest_jobs($limit){
        $this -> db -> select('job_ads.is_featured_job,job_ads.featured_job_status,job_ads.created_date as job_create_date,job_ads.text_description as job_description,job_ads.job_keys, companies.name as company_name, job_ads.title as job_title, job_ads.job_keys as job_key, job_ads.date_available as date_available, job_locations.name as location_name, job_locations.name as location_name, job_sub_categories.name as sub_categoris_name');
        $this -> db -> from('job_ads');
        $this -> db -> join('job_categories', 'using_job_category_id=job_category_id');
        $this -> db -> join('job_sub_categories', 'using_job_sub_category_id=job_sub_category_id','left');
       	$this -> db -> join('job_locations', 'using_job_location_id=job_location_id');
        //$this -> db -> join('employers', 'employers.employer_id=job_ads.using_employer_id');
       	$this -> db -> join('companies', 'companies.company_id=job_ads.using_company_id');
        $this -> db -> where('date_available>=CURDATE()');
		$this -> db -> where('job_ads.status','1');
		
		$this -> db -> order_by('job_ads.changed_date','DESC');
		$this -> db -> order_by('job_ads.is_featured_job','ASC');
		$this -> db -> order_by('job_ads.featured_job_status','DESC');
        $this -> db -> limit($limit);
        return $this -> db -> get();
    }
    /* This function use to count all jobs by categoy
     * $this->model_jobs->count_all_jobs();
     */
    public function count_all_jobs($categoryId){
    	$this -> db -> select('*');
        $this -> db -> join('job_categories', 'using_job_category_id=job_category_id');
        $this -> db -> join('job_sub_categories', 'using_job_sub_category_id=job_sub_category_id','left');
        $this -> db -> join('job_locations', 'using_job_location_id=job_location_id');
        $this -> db -> join('job_types', 'using_job_type_id=job_type_id');
        //$this -> db -> join('employers', 'employers.employer_id=job_ads.using_employer_id');
        $this -> db -> join('companies', 'companies.company_id=job_ads.using_company_id');
        $this -> db -> where('date_available>=CURDATE()');
		$this -> db -> where('job_ads.status','1');
		$this -> db -> order_by('job_ads.is_featured_job','ASC');
		$this -> db -> order_by('job_ads.featured_job_status','DESC');
		$this -> db -> order_by('job_ads.changed_date','DESC');
        if($categoryId!=NULL){
            $this -> db -> where('job_category_id',$categoryId);
        }
        return $this -> db -> count_all("job_ads");

    }
    /* This function use to retrieve jobs which depend on condition of category's id
     * $this->model_jobs->list_all_jobs_ajax(10,0,5); limit=10,start=0,categoryId=5
     */
    public function list_all_jobs_ajax($limit, $start, $categoryId) {
        $this -> db -> select('job_ads.is_featured_job,job_ads.featured_job_status,job_ads.created_date as job_create_date,job_ads.job_ads_id,job_ads.text_description as job_description,job_ads.job_keys, companies.name as company_name, job_ads.title as job_title, job_ads.date_available as date_available, job_locations.name as location_name, job_locations.name as location_name, job_sub_categories.name as sub_categoris_name');
        $this -> db -> from('job_ads');
        $this -> db -> join('job_categories', 'using_job_category_id=job_category_id');
        $this -> db -> join('job_sub_categories', 'using_job_sub_category_id=job_sub_category_id','left');
        $this -> db -> join('job_locations', 'using_job_location_id=job_location_id');
        $this -> db -> join('job_types', 'using_job_type_id=job_type_id');
        //$this -> db -> join('employers', 'employers.employer_id=job_ads.using_employer_id');
        $this -> db -> join('companies', 'companies.company_id=job_ads.using_company_id');
        $this -> db -> where('date_available>=CURDATE()');
		$this -> db -> where('job_ads.status','1');
        if($categoryId!=NULL){
            $this -> db -> where('job_category_id', $categoryId);
        }
		$this -> db -> order_by('job_ads.is_featured_job','ASC');
		$this -> db -> order_by('job_ads.featured_job_status','DESC');
		$this -> db -> order_by('job_ads.changed_date','DESC');
        $this -> db -> limit($limit,$start);
        return $this -> db -> get();
    }
    /* This function use to count all jobs by location
     * $this->model_jobs->count_all_jobs();
     */
    public function count_all_jobs_by_location($locationId){
    	$this -> db -> select('*');
        $this -> db -> join('job_categories', 'using_job_category_id=job_category_id');
        $this -> db -> join('job_sub_categories', 'using_job_sub_category_id=job_sub_category_id','left');
        $this -> db -> join('job_locations', 'using_job_location_id=job_location_id');
        $this -> db -> join('job_types', 'using_job_type_id=job_type_id');
        //$this -> db -> join('employers', 'employers.employer_id=job_ads.using_employer_id');
        $this -> db -> join('companies', 'companies.company_id=job_ads.using_company_id');
        $this -> db -> where('job_ads.status','1');
        $this -> db -> where('date_available>=CURDATE()');
        $this -> db -> where('job_location_id',$locationId);
		$this -> db -> order_by('job_ads.is_featured_job','ASC');
		$this -> db -> order_by('job_ads.featured_job_status','DESC');
		$this -> db -> order_by('job_ads.changed_date','DESC');
		return $this -> db -> count_all('job_ads');

    }
    /* This function use to retrieve jobs which depend on condition of location's id
     * $this->model_jobs->list_all_jobs_ajax(10,0,5); limit=10,start=0,locationId=5
     */
    public function list_all_jobs_by_loction_ajax($limit, $start, $locationId) {
        $this -> db -> select('job_ads.is_featured_job,job_ads.featured_job_status,job_ads.created_date as job_create_date,job_ads.job_ads_id,job_ads.text_description as job_description,job_ads.job_keys, companies.name as company_name, job_ads.title as job_title, job_ads.date_available as date_available, job_locations.name as location_name, job_locations.name as location_name, job_sub_categories.name as sub_categoris_name');
        $this -> db -> from('job_ads');
        $this -> db -> join('job_categories', 'using_job_category_id=job_category_id');
        $this -> db -> join('job_sub_categories', 'using_job_sub_category_id=job_sub_category_id','left');
        $this -> db -> join('job_locations', 'using_job_location_id=job_location_id');
        $this -> db -> join('job_types', 'using_job_type_id=job_type_id');
        //$this -> db -> join('employers', 'employers.employer_id=job_ads.using_employer_id');
        $this -> db -> join('companies', 'companies.company_id=job_ads.using_company_id');
        $this -> db -> where('job_ads.status','1');
        $this -> db -> where('date_available>=CURDATE()');
        $this -> db -> where('job_location_id', $locationId);
		$this -> db -> order_by('job_ads.is_featured_job','ASC');
		$this -> db -> order_by('job_ads.featured_job_status','DESC');
		$this -> db -> order_by('job_ads.changed_date','DESC');
        $this -> db -> limit($limit,$start);
        return $this -> db -> get();
    }
    /* This function use to count all jobs by company
     * $this->model_jobs->count_all_jobs();
     */
    public function count_all_jobs_by_company($companyId){
    	$this -> db -> select('*');
        $this -> db -> join('job_categories', 'using_job_category_id=job_category_id');
        $this -> db -> join('job_sub_categories', 'using_job_sub_category_id=job_sub_category_id','left');
        $this -> db -> join('job_locations', 'using_job_location_id=job_location_id');
        $this -> db -> join('job_types', 'using_job_type_id=job_type_id');
        //$this -> db -> join('employers', 'employers.employer_id=job_ads.using_employer_id');
        $this -> db -> join('companies', 'companies.company_id=job_ads.using_company_id');
        $this -> db -> where('job_ads.status','1');
        $this -> db -> where('date_available>=CURDATE()');
        $this -> db -> where('company_id',$companyId);
		$this -> db -> order_by('job_ads.is_featured_job','ASC');
		$this -> db -> order_by('job_ads.featured_job_status','DESC');
		$this -> db -> order_by('job_ads.changed_date','DESC');
		return $this->db->count_all('job_ads');


    }
    /* This function use to retrieve jobs which depend on condition of location's id
     * $this->model_jobs->list_all_jobs_ajax(10,0,5); limit=10,start=0,locationId=5
     */
    public function list_all_jobs_by_company_ajax($limit, $start, $companyId) {
        $this -> db -> select('job_ads.is_featured_job,job_ads.featured_job_status,job_ads.created_date as job_create_date,job_ads.job_ads_id,job_ads.text_description as job_description,job_ads.job_keys, companies.name as company_name, job_ads.title as job_title, job_ads.date_available as date_available, job_locations.name as location_name, job_locations.name as location_name, job_sub_categories.name as sub_categoris_name');
        $this -> db -> from('job_ads');
        $this -> db -> join('job_categories', 'using_job_category_id=job_category_id');
        $this -> db -> join('job_sub_categories', 'using_job_sub_category_id=job_sub_category_id','left');
        $this -> db -> join('job_locations', 'using_job_location_id=job_location_id');
        $this -> db -> join('job_types', 'using_job_type_id=job_type_id');
        //$this -> db -> join('employers', 'employers.employer_id=job_ads.using_employer_id');
        $this -> db -> join('companies', 'companies.company_id=job_ads.using_company_id');
         $this -> db -> where('job_ads.status','1');
        $this -> db -> where('date_available>=CURDATE()');
        $this -> db -> where('company_id',$companyId);
		$this -> db -> order_by('job_ads.is_featured_job','ASC');
		$this -> db -> order_by('job_ads.featured_job_status','DESC');
		$this -> db -> order_by('job_ads.changed_date','DESC');
        $this -> db -> limit($limit,$start);
        return $this -> db -> get();
    }
    /* This function use to retieve all sub categories which depend on category's id
     * $this->model_jobs->list_sub_category(3); categoryId=3
     */
    public function list_sub_category($categoryId) {
        $result = $this -> db -> query('SELECT c.name, c.job_sub_categories_keys ,  IFNULL(a.counts,0) AS count
           FROM mw_job_sub_categories AS c LEFT JOIN (
           SELECT using_job_sub_category_id, COUNT( * ) AS counts
           FROM mw_job_ads where mw_job_ads.status = 1 and date_available>CURDATE() GROUP BY using_job_sub_category_id
           ) AS a ON c.job_sub_category_id = a.using_job_sub_category_id
           WHERE c.using_job_category_id = ' . $categoryId . '
           ORDER BY c.job_sub_category_id 
        ');
        return $result;
    }
     /* This function use to retieve all sub categories which depend on category's id
     * $this->model_jobs->list_sub_category(3); categoryId=3
     */
    public function list_sub_category_($sub_categoryId) {
        $result = $this -> db -> query('SELECT c.name, c.job_sub_categories_keys ,  IFNULL(a.counts,0) AS count
           FROM mw_job_sub_categories AS c LEFT JOIN (
           SELECT using_job_sub_category_id, COUNT( * ) AS counts
           FROM mw_job_ads where mw_job_ads.status = 1 and date_available>=CURDATE() GROUP BY using_job_sub_category_id
           ) AS a ON c.job_sub_category_id = a.using_job_sub_category_id
           WHERE c.using_job_category_id = ' . $sub_categoryId . '
           ORDER BY c.job_sub_category_id 
        ');
        return $result;
    }
    public function count_all_jobs_by_sub($sub_categoryId){
    	$this -> db -> select('*');
    	$this -> db -> join('job_categories','using_job_category_id=job_category_id');
        $this -> db -> join('job_sub_categories','using_job_sub_category_id=job_sub_category_id','left');
        $this -> db -> join('job_locations','using_job_location_id=job_location_id');
        $this -> db -> join('job_types','using_job_type_id=job_type_id');
        $this -> db -> join('contact_persons','using_contact_person_id=contact_person_id');
        $this -> db -> join('job_term','using_job_term_id=job_term_id');
        $this -> db -> join('education_levels','using_education_level_id=education_level_id');
        //$this -> db -> join('employers','employers.employer_id=job_ads.using_employer_id');
        $this -> db -> join('companies', 'companies.company_id=job_ads.using_company_id');
        $this -> db -> where('job_ads.status','1');
        $this -> db -> where('date_available>=CURDATE()');
        if($sub_categoryId!=NULL){
            $this -> db -> where('using_job_sub_category_id',$sub_categoryId);
        }
		$this -> db -> order_by('job_ads.is_featured_job','ASC');
		$this -> db -> order_by('job_ads.featured_job_status','DESC');
		$this -> db -> order_by('job_ads.changed_date','DESC');
        return $this -> db -> count_all('job_ads');

    }
    public function list_all_jobs_ajax_($limit, $start, $sub_categoryId) {
        $this -> db -> select('job_ads.is_featured_job,job_ads.featured_job_status,job_ads.created_date as job_create_date,job_ads.text_description as job_description,job_ads.job_keys, companies.name as company_name, job_ads.title as job_title, job_ads.date_available as date_available, job_locations.name as location_name, job_locations.name as location_name, job_sub_categories.name as sub_categoris_name');
        $this -> db -> from('job_ads');
        $this -> db -> join('job_categories', 'using_job_category_id=job_category_id');
        $this -> db -> join('job_sub_categories', 'using_job_sub_category_id=job_sub_category_id','left');
        $this -> db -> join('job_locations', 'using_job_location_id=job_location_id');
        $this -> db -> join('job_types', 'using_job_type_id=job_type_id');
        $this -> db -> join('contact_persons', 'using_contact_person_id=contact_person_id');
        $this -> db -> join('job_term', 'using_job_term_id=job_term_id');
        $this -> db -> join('education_levels', 'using_education_level_id=education_level_id');
        //$this -> db -> join('employers', 'employers.employer_id=job_ads.using_employer_id');
        $this -> db -> join('companies', 'companies.company_id=job_ads.using_company_id');
         $this -> db -> where('job_ads.status','1');
        $this -> db -> where('date_available>=CURDATE()');
        if($sub_categoryId!=NULL){
            $this -> db -> where('using_job_sub_category_id', $sub_categoryId);
        }
		$this -> db -> order_by('job_ads.is_featured_job','ASC');
		$this -> db -> order_by('job_ads.featured_job_status','DESC');
		$this -> db -> order_by('job_ads.changed_date','DESC');
        $this -> db -> limit($limit,$start);
        return $this -> db -> get();
    }
    /* This function view job's detail which depend on job_key
     * $this->model_jobs->list_job_detail(1@#Kl$E); job_key=1@#Kl$E
     */
    public function list_job_detail($job_key) {
        $this -> db -> select('companies.address as address, companies.description as company_description,companies.company_keys as company_key,job_ads.created_date as job_created,job_term.name as job_term,job_types.name job_type, job_locations.name as location ,companies.name as company_name , companies.phone as company_phone, companies.fax as company_fax, companies.website as company_website,companies.logo as company_logo,job_ads.text_description as job_description,job_ads.salary as job_salary,job_ads.age as age,job_ads.hiring as job_hiring,job_ads.gender as gender,job_ads.date_available as date_available,job_ads.created_date as create_date,contact_persons.name as contact_name,contact_persons.phone as contact_phone,contact_persons.email as contact_email,job_term.name as job_term,education_levels.name as level,job_ads.text_requirements as job_requirements,job_ads.job_keys, companies.name as company_name, job_ads.title as job_title, job_ads.date_available as date_available, job_locations.name as location_name, job_locations.name as location_name, job_sub_categories.name as sub_categoris_name,posted_by');
        $this -> db -> from('job_ads');
        $this -> db -> join('job_categories', 'using_job_category_id=job_category_id');
        $this -> db -> join('job_sub_categories', 'using_job_sub_category_id=job_sub_category_id','left');
        $this -> db -> join('job_locations', 'using_job_location_id=job_location_id');
        $this -> db -> join('job_types', 'using_job_type_id=job_type_id');
        $this -> db -> join('contact_persons', 'using_contact_person_id=contact_person_id');
        $this -> db -> join('job_term', 'using_job_term_id=job_term_id');
        $this -> db -> join('education_levels', 'using_education_level_id=education_level_id');
       // $this -> db -> join('employers', 'employers.employer_id=job_ads.using_employer_id');
        $this -> db -> join('companies', 'companies.company_id=job_ads.using_company_id');
        $this -> db -> where('job_ads.job_keys', $job_key);
        return $this -> db -> get();
    }
    /* This function use to search job which need atleast one value
     * $this->model_jobs->list_job_search($keySearch=NULL, $sub_categoryKey= NULL, $locationName = NULL)
     */
    public function list_job_search($keySearch=NULL, $categoryKey= NULL, $locationName = NULL){
        $this -> db -> select('*');
    	$this -> db -> join('job_categories','using_job_category_id=job_category_id');
        $this -> db -> join('job_sub_categories','using_job_sub_category_id=job_sub_category_id','left');
        $this -> db -> join('job_locations','using_job_location_id=job_location_id');
        $this -> db -> join('job_types','using_job_type_id=job_type_id');
        $this -> db -> join('contact_persons','using_contact_person_id=contact_person_id');
        $this -> db -> join('job_term','using_job_term_id=job_term_id');
        $this -> db -> join('education_levels','using_education_level_id=education_level_id');
       //$this -> db -> join('employers','employers.employer_id=job_ads.using_employer_id');
        $this -> db -> join('companies', 'companies.company_id=job_ads.using_company_id');
        if($keySearch!=NULL){
            $this -> db -> like('job_ads.title',$keySearch);
            $this -> db -> or_like('companies.name',$keySearch);
        }
        if($categoryKey!=NULL){
        	if (strpos($categoryKey,'-') !== false) {
			  	$splite_category = explode("-", $categoryKey);
				if($splite_category[1]==0){
					$this -> db -> where('job_categories.job_category_id',$splite_category[0]);
				}else{
					$this -> db -> where('job_sub_categories.job_sub_category_id',$splite_category[1]);
				}  
			}
            
        }
        if($locationName!=NULL){
            $this -> db -> where('job_locations.name',$locationName);
        }
		$this -> db -> order_by('job_ads.is_featured_job','ASC');
		$this -> db -> order_by('job_ads.featured_job_status','DESC');
		$this -> db -> order_by('job_ads.changed_date','DESC');
	    return $this -> db -> count_all('job_ads'); 
    }
    /* This function use to search job which need atleast one value
     * $this->model_jobs->load_job_search($limit, $start, $keySearch=NULL, $sub_categoryKey= NULL, $locationName = NULL)
     */
    public function load_job_search($limit, $start, $keySearch=NULL, $categoryKey= NULL, $locationName = NULL){
        $this -> db -> select('job_ads.is_featured_job,job_ads.featured_job_status,job_ads.created_date as job_create_date,job_ads.text_description as job_description,job_ads.job_keys, companies.name as company_name, job_ads.title as job_title, job_ads.date_available as date_available, job_locations.name as location_name, job_locations.name as location_name, job_sub_categories.name as sub_categoris_name');
        $this -> db -> from('job_ads');
        $this -> db -> join('job_categories', 'using_job_category_id=job_category_id');
        $this -> db -> join('job_sub_categories', 'using_job_sub_category_id=job_sub_category_id','left');
        $this -> db -> join('job_locations', 'using_job_location_id=job_location_id');
        $this -> db -> join('job_types', 'using_job_type_id=job_type_id');
        $this -> db -> join('contact_persons', 'using_contact_person_id=contact_person_id');
        $this -> db -> join('job_term', 'using_job_term_id=job_term_id');
        $this -> db -> join('education_levels', 'using_education_level_id=education_level_id');
        //$this -> db -> join('employers', 'employers.employer_id=job_ads.using_employer_id');
       	$this -> db -> join('companies', 'companies.company_id=job_ads.using_company_id');
        if($keySearch!=NULL){
            $this -> db -> like('job_ads.title',$keySearch);
            $this -> db -> or_like('companies.name',$keySearch);
        }
        if($categoryKey!=NULL){
        	if (strpos($categoryKey,'-') !== false) {
			  	$splite_category = explode("-", $categoryKey);
				if($splite_category[1]==0){
					$this -> db -> where('job_categories.job_category_id',$splite_category[0]);
				}else{
					$this -> db -> where('job_sub_categories.job_sub_category_id',$splite_category[1]);
				}  
			}
            
        }
        if($locationName!=NULL){
            $this -> db -> where('job_locations.name',$locationName);
        }
		$this -> db -> order_by('job_ads.is_featured_job','ASC');
		$this -> db -> order_by('job_ads.featured_job_status','DESC');
		$this -> db -> order_by('job_ads.changed_date','DESC');
        $this -> db -> limit($limit,$start);
	    return $this -> db -> get(); 
    }
    /* This function list information about the company which depond on employer's' Id
     * $this->model_jobs->list_company_info($employerId)
     */
    public function list_company_info($employerId){
        $this -> db -> select('companies.name as company_name, companies.company_keys as company_key , employers.token_key as token_key, companies.description as company_description, companies.website as company_website, companies.address as company_address, companies.logo as company_logo, employers.username as employer_username, employers.email as employer_email, employers.mobile as employer_mobile');
        $this -> db -> from('employers');
        $this -> db -> join('companies', 'companies.using_employer_id=employers.employer_id');
        $this -> db -> where('employers.employer_id',$employerId);
        return $this -> db -> get();
    }
    /* This function list all job which depend on employer's Id
     * $this->model_jobs->list_job_by_employer($employerId)
     */
    public function list_job_by_employer($employerId){
        $this -> db -> select('job_ads.is_featured_job,job_ads.created_date as job_create_date,job_ads.job_keys as job_key, job_ads.title as job_title, job_ads.hiring as job_hire, job_ads.date_available as date_available, job_locations.name as location_name, job_sub_categories.name as sub_categoris_name');
        $this -> db -> from('job_ads');
        $this -> db -> join('job_categories', 'using_job_category_id=job_category_id');
        $this -> db -> join('job_sub_categories', 'using_job_sub_category_id=job_sub_category_id','left');
        $this -> db -> join('job_locations', 'using_job_location_id=job_location_id');
        $this -> db -> join('contact_persons', 'using_contact_person_id=contact_person_id');
        $this -> db -> join('employers', 'employers.employer_id=job_ads.using_employer_id');
        $this -> db -> join('companies', 'companies.company_id=job_ads.using_company_id');
        $this -> db -> where('job_ads.status','1');
        $this -> db -> where('employers.employer_id',$employerId);
        $this -> db -> where('employers.employer_id !=','0');
		$this -> db -> order_by('job_ads.changed_date','DESC');
        return $this -> db -> get();
    }
    /* This function use to retrive employer banner as fearture employer
     * $this->model_jobs->fearture_employer()
     */
    public function fearture_employer(){
        $this -> db -> select('companies.name as company_name, companies.company_keys as company_key, employers.token_key as token_key, companies.company_id as company_id, employer_banners.img_name,employer_banners.using_link_type_id as using_link_type_id , employer_banners.link as link');
        $this -> db -> from('companies');
        $this -> db -> join('employers', 'companies.using_employer_id = employers.employer_id');
        $this -> db -> join('employer_banners', 'employer_banners.using_employer_id = employers.employer_id');
        $this -> db -> join('link_types', 'link_types.link_type_id = employer_banners.using_link_type_id');
        $this -> db -> where('employer_banners.status',1);
		$this -> db -> where('available_date>=CURDATE()');
        return $this -> db -> get(); 
    }
	
	public function fearture_job(){
		$this -> db -> select('job_ads_id,title,job_keys,companies.name');
        $this -> db -> from('job_ads');
        //$this -> db -> join('employers', 'employers.employer_id=job_ads.using_employer_id');
        $this -> db -> join('companies', 'companies.company_id=job_ads.using_company_id');
        $this -> db -> where('date_available>=CURDATE()');
		$this -> db -> where('is_featured_job',"YES");
		$this -> db -> where('featured_job_status',1);
        $this -> db -> order_by('job_ads_id','RANDOM');
        $this -> db -> limit(7);
        return $this -> db -> get();
	}

}

